<template>
  <div class="goods_list">
    <div class="goods_item" v-for="item in list" :key="item.id" @click="goodsInfo(item.id)">
      <img :src="item.img_url" alt>
      <h1>{{ item.title }}</h1>
      <div class="item_content">
        <p class="price">
          <span class="new">{{ item.sell_price }}</span>
          <span class="old">{{ item.market_price }}</span>
        </p>
        <p class="sell">
          <span>热卖中</span>
          <span>{{ item.market_stock_quantity }}</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  created() {
    this.getData();
  },
  data() {
    return {
      list: [],
      pageIndex: 1
    };
  },
  methods: {
    getData() {
      this.$http.get("api/getgoods?pageindex=" + this.pageIndex).then(data => {
        if (data.body.status === 0) {
          console.log(data.body.message);
          this.list = this.list.concat(data.body.message);
        }
      });
    },
    getMore(id) {
      this.pageIndex++;
      this.getData();
    },
    //编程路由跳转
    goodsInfo(id) {
      this.$router.push("/home/goodsInfo/" + id);
    }
  }
};
</script>
<style lang="scss" scoped>
.goods_list {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 3px 5px;
  .goods_item {
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 4px #999;
    margin: 5px 0;
    min-height: 278px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 3px;
    h1 {
      font-size: 16px;
    }
    img {
      width: 100%;
    }
    .item_content {
      padding: 5px;
      background-color: #eee;
      p {
        margin: 0;
      }
      .price {
        .new {
          color: red;
          font-weight: 700;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 15px;
        }
      }
      .sell {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
      }
    }
  }
}
</style>
